package com.example.yuejianapp14.Activity.Model;

import com.example.yuejianapp14.Activity.JavaBean.Search;
import com.example.yuejianapp14.Activity.JavaBean.Video1;
import com.example.yuejianapp14.Activity.Listener.SearchListener;
import com.example.yuejianapp14.Activity.Listener.VideoListener;
import com.example.yuejianapp14.Activity.Servics.SerachServics;
import com.example.yuejianapp14.Activity.Servics.VideoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by 张森 on 2017/11/13.
 */

public class SearchModel {
    private Retrofit retrofit;
    private String BASEURL = "http://10.0.2.2/YueJian/index.php/Api/Club/";

    public SearchModel() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void search(String content,final SearchListener listener){
        SerachServics serachServics=retrofit.create(SerachServics.class);
        Call<List<Search>> call=serachServics.search(content);
        call.enqueue(new Callback<List<Search>>() {
            @Override
            public void onResponse(Call<List<Search>> call, Response<List<Search>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                }else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Search>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
